//
//  CollectViewController.swift
//  UUCartoon
//
//  Created by Galaxy on 2021/6/29.
//  Copyright © 2021 qykj. All rights reserved.
//

import UIKit
import UICollectionViewLeftAlignedLayout
import EmptyDataSet_Swift
class CollectViewController: BaseViewController {
    var listArr:[CartoonModel] = []{
        didSet{
            mainTable.listArr = listArr
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        title = "收藏列表"
        getListData()
    }
    
    func getListData(){
        listArr = SqlTool.init().getCollect()
    }
    lazy var mainTable: UUTableView = {
        let tableView = UUTableView.init(frame: .zero, style: .plain)
        view.addSubview(tableView)
        tableView.estimatedRowHeight = 150
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        tableView.register(UINib.init(nibName: "ComicTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "cell")
        tableView.cellForRow {[weak self] (indexPath) in
            let model = self!.listArr[indexPath.row]
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! ComicTableViewCell
            cell.model = model
            cell.rankViewConstraintWidth.constant = 40
            return cell
        }
        tableView.cellItemDidSelected {[weak self] (indexPath) in
            let model = self!.listArr[indexPath.row]
            let VC = ChapterViewController.init()
            VC.type = model.type
            VC.detailUrl = model.detailUrl
            VC.cartoon_id = model.cartoon_id
            VC.deleteCollectBlock = {
                self!.getListData()
            }
            self?.navigationController?.pushViewController(VC, animated: true)
        }
        tableView.emptyDataSetView { emptyView in
            emptyView.detailLabelString(NSAttributedString.init(string: "快去收藏喜欢的内容吧")).image(UIImage.init(named: "empty_img"))
        }
        return tableView
    }()

}
